<h2 class="dialog_title"><span>Perolehan Reward/Punishment</span></h2>
<div class="dialog_content" style="padding: 10px 20px; width:800px">
<table width="100%" border="0" cellpadding="5" cellspacing="0">
	<tr>
    	<?php $dept = mysql_fetch_assoc(departemen_load($deptID))?>
		<td width="80">Departemen : </td>
        <td><strong><?php echo $dept['NAMA_DEPARTMENT']?></strong></td>
	</tr>
	<tr>
    	<td>Periode : </td>
		<td><strong><?php echo date('m-Y', $startPeriode) ?> - <?php echo date('m-Y', $endPeriode) ?></strong></td>
	</tr>
</table>
<table style="border:1px solid #457A3F;" width="100%" border="0" cellpadding="5" cellspacing="0">
  <tr class="header">
  	<th align="left"><span class="colorWhite">Periode</span></th>
    <th align="left"><span class="colorWhite">Jenis</span></th>
    <th align="left"><span class="colorWhite">Bidang</span></th>
    <th align="left"><span class="colorWhite">Tingkat</span></th>
    <th align="left"><span class="colorWhite">Kategori</span></th>
    <th align="right"><span class="colorWhite">Jumlah <?php echo $jenis==="prestasi"? "Reward" : "Punishment"?></span></th>
  </tr>
  <tbody id="searchKary-table" style="overflow:scroll; height:200px" >
<?php
		$result = mysql_query(
			"SELECT DATE_FORMAT(a.PERB_TGL,'%Y-%m') as PERB_TGL, a.KODE_KARYAWAN, b.NAMA_KARYAWAN, e.NAMA_DEPARTMENT, a1.DETACHIEV_ID, 
				f.ACHIEV_JENIS, f.ACHIEV_BIDANG, g.DETACHIEV_TINGKAT, g.DETACHIEV_NAMA,
				COUNT(a1.DETACHIEV_ID) AS COUNT
			FROM perbuatan as a, detil_perbuatan as a1, 
				data_karyawan as b, relasi_div_jab_din as c, 
				dep_divisi_jabatan as d, data_department as e,
				prestasipelanggaran as f, detil_prestasi_pelanggaran as g
			WHERE a.PERB_NO = a1.PERB_NO AND
				a1.DEPERB_STATUS='2' AND 
				a.KODE_KARYAWAN = b.KODE_KARYAWAN AND
				b.KODE_KARYAWAN  = c.KODE_KARYAWAN AND
				c.ID_DEP_DIV_JAB = d.ID_DEP_DIV_JAB AND
				d.ID_DEPARTMENT  = e.ID_DEPARTMENT AND
				f.ACHIEV_ID = g.ACHIEV_ID AND 
				g.DETACHIEV_ID = a1.DETACHIEV_ID AND
				e.ID_DEPARTMENT  = '$deptID' AND 
				DATE_FORMAT( a.PERB_TGL, '%Y-%m' ) BETWEEN 
					DATE_FORMAT('".date('Y-m-d', $startPeriode)."', '%Y-%m' ) AND 
					DATE_FORMAT('".date('Y-m-d', $endPeriode)."', '%Y-%m')
				
			GROUP BY KODE_KARYAWAN, PERB_TGL, DETACHIEV_ID
			ORDER BY NAMA_KARYAWAN, PERB_TGL, ACHIEV_JENIS, ACHIEV_BIDANG");
//		f.ACHIEV_JENIS = '$jenis'
	$count=0;
	
	$oldKaryGroup = "";
?>
<?php while ($row = mysql_fetch_assoc($result)):?>
<?php $avgcounter += $row['COUNT']?>
<?php if (strtolower($row['ACHIEV_JENIS']) != $jenis) continue;?>
<?php if ($oldKaryGroup != $row['KODE_KARYAWAN']):?>
  <tr bgcolor="#CCCCCC">
  	<td colspan="6"><?php echo $row['NAMA_KARYAWAN'] ." (". $row['KODE_KARYAWAN'] .")"?></td>
  </tr>
  <?php $oldKaryGroup=$row['KODE_KARYAWAN'] ?>
<?php endif?>
  <tr <?php echo tag_zebra($z++)?>>
  	<td><?php echo $row['PERB_TGL']?></td>
    <td><?php echo $row['ACHIEV_JENIS']?></td>
    <td><?php echo $row['ACHIEV_BIDANG']?></td>
    <td><?php echo $row['DETACHIEV_TINGKAT']?></td>
    <td><?php echo $row['DETACHIEV_NAMA']?></td>
    <td align="right"><?php echo $row['COUNT']?></td>
    <?php $count += $row['COUNT']; ?>
  </tr>
<?php endwhile;?>
  </tbody>
  <tr class="header">
	<th align="right" colspan="5"><span class="colorWhite">Total <?php echo $jenis=="prestasi"? "Reward" : "Punishment"?> : </span></th>
    <th align="right"><span class="colorWhite"><?php echo $count?></span></th>
  </tr>
  <tr class="header">
	<th align="right" colspan="5"><span class="colorWhite">Jumlah Reward & Punishment : </span></th>
    <th align="right"><span class="colorWhite"><?php echo $avgcounter?></span></th>
  </tr>
  <tr class="header">
	<th align="right" colspan="5"><span class="colorWhite">Rata - rata Reward &amp; Punishment : </span></th>
    <th align="right"><span class="colorWhite"><?php echo number_format($count/$avgcounter, 2)?></span></th>
  </tr>
</table>
</div>
<div class="dialog_buttons"><input type="button" value="Close" name="close" onclick="FBModal_hide()" /></div>